package com.qxglxt.qxgl.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import lombok.Data;

@Data
@Table
@Entity
public class Users {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;//编号
    @Column(unique = true)
    private String loginName;//登录名
    private String password;//密码
    @Column(length = 10,columnDefinition = "String default 否")
    private String isLockout;//是否锁定
    @CreationTimestamp//自动生成系统时间，格式为yyyy-MM-dd hh:MM:ss
    private Date lastLoginTime;//最后一次登陆时间
    @CreationTimestamp//自动生成系统时间，格式为yyyy-MM-dd hh:MM:ss
    private Date createTime;//账号创立时间
    private String psdWrongTime;//密码错误次数
    @CreationTimestamp//自动生成系统时间，格式为yyyy-MM-dd hh:MM:ss
    private Date lockTime;//被锁定时间
    private String protectEMail;//密保邮箱
    @Column(unique = true,length = 11)
    private String protectMtel;//密保手机号
    @ManyToOne(targetEntity = Roles.class)
    private Roles roleId;//角色id

	@JsonIgnore
	@ManyToMany(fetch = FetchType.LAZY)
	@Cascade(CascadeType.SAVE_UPDATE)
	@JoinTable(
			name = "user_roles",
			joinColumns =  {@JoinColumn(name="users_id")},
			inverseJoinColumns = {@JoinColumn(name="role_id")}
			)
	@NotFound(action = NotFoundAction.IGNORE)
	private Set<Roles> rolesSet = new HashSet<Roles>();
    

}